# # 字典中的值又是一个字典(嵌套的字典)
# girls = {
#     1001: {'name': '刘亦菲', 'sex': True, 'age': 22, 'place': '山西大同'},
#     1002: {'name': '赫本', 'sex': True, 'age': 23, 'place': '河北保定'},
#     1003: {'name': '李小璐', 'sex': True, 'age': 20, 'place': '四川广元'}
# }
#
# # 使用get方法通过键获取对应的值，如果取不到不会引发KeyError异常而是返回None或设定的默认值
# print(girls.get(1002))    # {'name': '白元芳', 'sex': True, 'age': 23, 'place': '河北保定'}
# print(girls.get(1005))    # None
# print(girls.get(1005, {'name': '无名氏'}))    # {'name': '无名氏'}
#
# # 获取字典中所有的键
# print(girls.keys())      # dict_keys([1001, 1002, 1003])
# # 获取字典中所有的值
# print(girls.values())    # dict_values([{...}, {...}, {...}])
# # 获取字典中所有的键值对
# print(girls.items())     # dict_items([(1001, {...}), (1002, {....}), (1003, {...})
#
# for key,value in girls.items():
#     print(key,'->',value)
#
# g1=girls.popitem()
# print(g1)
# print(girls)


import time


# 定义数字时钟类
class Clock(object):
    """数字时钟"""

    def __init__(self, hour=0, minute=0, second=0):
        """初始化方法
        :param hour: 时
        :param minute: 分
        :param second: 秒
        """
        self.hour = hour
        self.min = minute
        self.sec = second

    def run(self):
        """走字"""
        self.sec += 1
        if self.sec == 60:
            self.sec = 0
            self.min += 1
            if self.min == 60:
                self.min = 0
                self.hour += 1
                if self.hour == 24:
                    self.hour = 0

    def show(self):
        """显示时间"""
        return f'{self.hour:0>2d}:{self.min:0>2d}:{self.sec:0>2d}'


# 创建时钟对象
clock = Clock(23, 59, 58)
while True:
    # 给时钟对象发消息读取时间
    print(clock.show())
    # 休眠1秒钟
    time.sleep(1)
    # 给时钟对象发消息使其走字
    clock.run()